#!/usr/bin/env/python3.7
# -*- coding: utf-8 -*-

"""
@File    : app_request_mysql.py
@Time    : 12/15/2021
@Author  : Silence
@Version : 1.0
@Contact : silence2021silence@163.com
@License : (C)Copyright 2021-2021, Silence
@Desc    : None
"""

import datetime
import pymysql
import get_localhost_ip_address


database = pymysql.connect(host="120.24.51.156", user="dormitory_system", password="123456",
                                    database="dormitory_system", charset="utf8")

class CheckAudio():
    def check_audio():
        local_host_ip_address = get_localhost_ip_address.GetLocalHostIPAddress.get_localhost_ip_address()
        cursor = database.cursor(cursor=pymysql.cursors.DictCursor)
        sql_1 = """
                select
                	id
                from
                	admin_audio_message
                where
                    ip_address = '%s'
                """
        sql_2 = sql_1 % (local_host_ip_address)
        print(local_host_ip_address)
        cursor.execute(sql_2)
        result = cursor.fetchall()
        id_list = []
        for r in result:
            id_ = r["id"]
            id_list.append(id_)
        if id_list == []:
            return 'none'
        else:
            return id_list

if __name__ == '__main__':
    CheckAudio.check_audio()